package bind

import (
	"net/http"
	"strings"
)

//回调方法
type CallFunc func(string) bool

//
func Map(data map[string]string) *Bind {
	o := new(Bind)
	o.Data = data
	o.must = make(map[string]bool)
	o.omit = make(map[string]bool)
	return o
}

//绑定表单
func Form(req *http.Request) *Bind {
	req.ParseMultipartForm(32 << 20) // 32 MB
	data := map[string]string{}
	if req.MultipartForm != nil && req.MultipartForm.File != nil {
		for k, v := range req.MultipartForm.Value {
			data[k] = strings.TrimSpace(v[0])
		}
	} else {
		for k, v := range req.PostForm {
			data[k] = strings.TrimSpace(v[0])
		}
	}
	return Map(data)
}

//绑定url查询属性
func Query(req *http.Request) *Bind {
	data := map[string]string{}
	for k, v := range req.URL.Query() {
		data[k] = strings.TrimSpace(v[0])
	}
	return Map(data)
}
